package com.usian.wemedia.controller.v1;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.usian.apis.wemedia.WmUserControllerApi;
import com.usian.model.common.dtos.ResponseResult;
import com.usian.model.media.pojos.WmUser;
import com.usian.wemedia.service.impl.WmUserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class WmUserController implements WmUserControllerApi {
    @Autowired
    private WmUserServiceImpl wmUserService;
    @PostMapping("/api/v1/user/save")
    @Override
    public ResponseResult save(@RequestBody WmUser wmUser) {
        if (wmUser==null || wmUser.getName()==null || wmUser.getApUserId()==null) return wmUserService.errorResult;
        wmUserService.save(wmUser);
        return wmUserService.sucResult;
    }
    @GetMapping("/api/v1/user/findByName/{name}")
    @Override
    public WmUser findByName(@PathVariable String name) {
        if (name ==null)return null;
        List<WmUser> list = wmUserService.list(Wrappers.<WmUser>lambdaQuery().eq(WmUser::getName, name));
        return list!=null&&list.size()!=0?list.get(0):null;
    }
    @GetMapping("/api/v1/user/findOne/{id}")// /api/v1/user/save/findOne/{id}
    @Override                   // /api/v1/user/save/findOne/{id}
    public WmUser findWmUserById(@PathVariable("id") Integer id) {
        return wmUserService.getById(id);
    }
}
